package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.PracticeAppointmentDto;
import com.ruoyi.training.vo.PracticeAppointmentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.PracticeAppointment;
import com.ruoyi.training.service.IPracticeAppointmentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实践预约Controller
 *
 * @author WorrilessGo
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/practiceAppointment")
public class PracticeAppointmentController extends BaseController
{
    @Autowired
    private IPracticeAppointmentService practiceAppointmentService;

    /**
     * 查询实践预约列表
     */
    @RequiresPermissions("training:practiceAppointment:list")
    @GetMapping("/list")
    public TableDataInfo list(PracticeAppointment practiceAppointment)
    {
        startPage();
        List<PracticeAppointment> list = practiceAppointmentService.selectPracticeAppointmentList(practiceAppointment);
        return getDataTable(list);
    }

    /**
     * 条件查询实践预约列表
     * lqx
     */
//    @RequiresPermissions("training:practiceAppointment:list")
    @GetMapping("/selectListByQuery")
    public TableDataInfo selectListByQuery( PracticeAppointmentDto practiceAppointmentDto)
    {
        startPage();
        List<PracticeAppointmentVo> list = practiceAppointmentService.selectPracticeAppointmentListByQuery(practiceAppointmentDto);
        return getDataTable(list);
    }

    /**
     * 通过班级id查询实践预约列表
     * lqx
     */
//    @RequiresPermissions("training:practiceAppointment:list")
    @GetMapping(value ="/selectListByClassId/{classId}")
    public List<PracticeAppointmentVo> selectListByClassId(@PathVariable("classId")String classId)
    {
        return practiceAppointmentService.selectListByClassId(classId);
    }

    /**
     * 导出实践预约列表
     */
    @RequiresPermissions("training:practiceAppointment:export")
    @Log(title = "实践预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeAppointment practiceAppointment)
    {
        List<PracticeAppointment> list = practiceAppointmentService.selectPracticeAppointmentList(practiceAppointment);
        ExcelUtil<PracticeAppointment> util = new ExcelUtil<PracticeAppointment>(PracticeAppointment.class);
        util.exportExcel(response, list, "实践预约数据");
    }

    /**
     * 获取实践预约详细信息
     */
    @RequiresPermissions("training:practiceAppointment:query")
    @GetMapping(value = "/{practiceAppointmentId}")
    public AjaxResult getInfo(@PathVariable("practiceAppointmentId") String practiceAppointmentId)
    {
        return success(practiceAppointmentService.selectPracticeAppointmentByPracticeAppointmentId(practiceAppointmentId));
    }

    /**
     * 新增实践预约
     */
    @RequiresPermissions("training:practiceAppointment:add")
    @Log(title = "实践预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeAppointment practiceAppointment)
    {
        return toAjax(practiceAppointmentService.insertPracticeAppointment(practiceAppointment));
    }

    /**
     * 新增实践预约(分配班级)
     * lqx
     */
//    @RequiresPermissions("training:practiceAppointment:add")
    @Log(title = "实践预约", businessType = BusinessType.INSERT)
    @PostMapping("/insertPracticeAppointment")
    public AjaxResult insertPracticeAppointment(@RequestBody PracticeAppointmentDto practiceAppointmentDto)
    {
        System.out.println(practiceAppointmentDto);
        return toAjax(practiceAppointmentService.insertPracticeAppointmentWithClass(practiceAppointmentDto));
    }

    /**
     * 修改实践预约
     */
    @RequiresPermissions("training:practiceAppointment:edit")
    @Log(title = "实践预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeAppointment practiceAppointment)
    {
        return toAjax(practiceAppointmentService.updatePracticeAppointment(practiceAppointment));
    }

    /**
     * 修改实践预约(分配班级)
     * lqx
     */
//    @RequiresPermissions("training:practiceAppointment:edit")
    @Log(title = "实践预约", businessType = BusinessType.UPDATE)
    @PutMapping("/editPracticeAppointment")
    public AjaxResult editPracticeAppointment(@RequestBody PracticeAppointmentDto practiceAppointmentDto)
    {
        return toAjax(practiceAppointmentService.editPracticeAppointment(practiceAppointmentDto));
    }

    /**
     * 删除实践预约
     */
    @RequiresPermissions("training:practiceAppointment:remove")
    @Log(title = "实践预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{practiceAppointmentIds}")
    public AjaxResult remove(@PathVariable String[] practiceAppointmentIds)
    {
        return toAjax(practiceAppointmentService.deletePracticeAppointmentByPracticeAppointmentIds(practiceAppointmentIds));
    }

    /**
     * 删除实践预约(分配班级)
     * lqx
     */
//    @RequiresPermissions("training:practiceAppointment:remove")
    @Log(title = "实践预约", businessType = BusinessType.DELETE)
    @DeleteMapping("/removePracticeAppointment/{practiceAppointmentIds}")
    public AjaxResult removePracticeAppointment(@PathVariable String[] practiceAppointmentIds)
    {
        return toAjax(practiceAppointmentService.removePracticeAppointmentByPracticeAppointmentIds(practiceAppointmentIds));
    }

}
